package edu.faytechcc.csc251.mvc.concrete;

import edu.faytechcc.csc251.mvc.AbstractModel;
import java.awt.Color;

/**
 *
 * @author Mr. Bryan
 */
public class ColorModel extends AbstractModel {

    private Color color;

    public void initColorModel() {
        this.setColor(Color.LIGHT_GRAY);
    }
    
    public void initColorModel(Color color) {
        this.setColor(color);
    }
    
    /**
     * @return the color
     */
    public Color getColor() {
        return color;
    }

    public int getRed() {
        return this.color.getRed();
    }
    
    public int getGreen() {
        return this.color.getGreen();
    }
    
    public int getBlue() {
        return this.color.getBlue();
    }

    /**
     * @param color the color to set
     */
    public void setColor(Color color) {
        Color oldColor = this.color;
        this.color = color;
        this.firePropertyChange(ColorProperties.COLOR, oldColor, color);
    }

    public void setRed(int red) {
        if (red < 0 || red > 255) {
            throw new IllegalArgumentException("Red must be 0-255: " + red);
        }
        Color oldColor = this.color;
        this.color = new Color(red, this.color.getGreen(), this.color.getBlue());
        this.firePropertyChange(ColorProperties.RED, oldColor, color);
    }
    
    public void setGreen(int green) {
        if (green < 0 || green > 255) {
            throw new IllegalArgumentException("Green must be 0-255: " + green);
        }
        Color oldColor = this.color;
        this.color = new Color(this.color.getRed(), green, this.color.getBlue());
        this.firePropertyChange(ColorProperties.GREEN, oldColor, color);
    }
    
    public void setBlue(int blue) {
        if (blue < 0 || blue > 255) {
            throw new IllegalArgumentException("Blue must be 0-255: " + blue);
        }
        Color oldColor = this.color;
        this.color = new Color(this.color.getRed(), this.color.getGreen(), blue);
        this.firePropertyChange(ColorProperties.BLUE, oldColor, color);
    }    
}
